package models

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

/**
create table video_call_materials_audit(
    id bigint auto_increment primary key,
    anchor_id bigint default 0 not null comment '主播id',
    status  tinyint default 0 not null comment '视频资料审核状态: 1: 待审核 2: 审核通过 3: 审核不通过',
    op_id bigint default 0 not null comment '操作人id',
    op_name varchar(20) default '' not null comment '操作人姓名',
    op_plat int default 0 not null comment '操作人平台',
    reason varchar(200) default '' not null comment '驳回原因',
    is_delete tinyint default 0 not null comment '是否删除（0:未删除 1:已删除）,提交新资料时旧资料变更为已删除',
    apply_time bigint not null default 0 comment '申请时间',
    audit_time bigint not null default 0 comment '审核时间',
    delete_time bigint not null default 0 comment '删除时间',
    create_time bigint not null default (unix_timestamp()) comment '创建时间',
    update_time bigint not null default 0 comment '更新时间',
    index idx_anchor_id(anchor_id)
)engine=innodb default charset=utf8mb4 comment='视频资料审核表';
*/

type Video_call_materials_audit struct {
	Id         int64  `orm:"auto" json:"id"`
	AnchorId   int64  `json:"anchor_id"`
	Status     int8   `json:"status"`
	OpId       int64  `json:"op_id"`
	OpName     string `json:"op_name"`
	OpPlat     int    `json:"op_plat"`
	Reason     string `json:"reason"`
	IsDelete   int8   `json:"is_delete"`
	ApplyTime  int64  `json:"apply_time"`
	AuditTime  int64  `json:"audit_time"`
	DeleteTime int64  `json:"delete_time"`
	CreateTime int64  `json:"create_time"`
	UpdateTime int64  `json:"update_time"`
}

type AuditMaterialListItem struct {
	Id            int64
	MaterialsType int
	Content       string
	ContentType   int
	Reason        string
}

func init() {
	orm.RegisterModel(new(Video_call_materials_audit))
}

func GetVideo_call_materials_auditByAnchorId(anchorId int64) (m Video_call_materials_audit, err error) {
	o := orm.NewOrm()
	m = Video_call_materials_audit{}
	err = o.QueryTable(new(Video_call_materials_audit)).Filter("anchor_id", anchorId).Filter("is_delete", 0).Limit(1).One(&m)
	return
}

func AddVideo_call_materials_audit(m *Video_call_materials_audit) (id int64, err error) {
	o := orm.NewOrm()
	id, err = o.Insert(m)
	return
}

func DeleteHistoryVideo_call_materials_audit(anchorId int64, id int64) (num int64, err error) {
	o := orm.NewOrm()
	timestamp := time.Now().Unix()
	num, err = o.QueryTable(new(Video_call_materials_audit)).Filter("anchor_id", anchorId).Filter("is_delete", 0).Exclude("id", id).Update(orm.Params{
		"update_time": timestamp,
		"delete_time": timestamp,
		"is_delete":   1,
	})
	return
}
